﻿<%@ Page Title="开店计划" Language="C#" MasterPageFile="~/master/m.master" %>

<script runat="server"></script>
<asp:Content ID="Content3" ContentPlaceHolderID="head" runat="Server">
    <link href="../assets/css/plugins/footable/footable.core.css" rel="stylesheet">
    <link href="../assets/css/shelf/base.css" rel="stylesheet">
    <link href="../assets/css/plugins/webuploader/webuploader.css" rel="stylesheet" />
    <link href="../assets/img/validate/validate.css" rel="stylesheet">
    <link href="../assets/css/plugins/iCheck/customsmall.css" rel="stylesheet" />
    <link href="../assets/css/plugins/stepper/stepper.widget.css" rel="stylesheet" />
    <link href="../assets/css/plugins/boxdrop/boxDrop.css" rel="stylesheet" />
    <link href="../assets/css/plugins/bootstrap-datepicker/bootstrap-datepicker.min.css" rel="stylesheet" />
    <style type="text/css">
        .system-box .right-side {
            width: 98%;
        }

        .condition, .condition-title {
            border-bottom: 1px solid #dfdfdd;
        }

        .form-group label {
            max-width: 70px;
            margin-left: 5px;
            padding-left: 1px;
            padding-right: 1px;
        }

        @media (min-width: 750px) {
            .modal-dialog {
                width: 400px;
            }

            .footable {
                border-bottom: 1px solid #dfdfdd;
                border-left: 1px solid #dfdfdd;
            }

                .footable th,
                .footable td {
                    border-top: 1px solid #dfdfdd;
                    border-right: 1px solid #dfdfdd;
                    text-align: center;
                }

            .tb-head-container {
                padding-right: 6px;
                background: #fff;
            }

            .tb-body-container {
                overflow-x: hidden;
                padding-right: 0px;
                background: #fff;
            }
            /*所有表格行高缩小*/
            .ibox-content .table > tbody > tr > td, .table > tbody > tr > th, .table > tfoot > tr > td, .table > tfoot > tr > th, .table > thead > tr > td, .table > thead > tr > th {
                padding: 1px !important;
            }
        }

        #addWindow .form-group label {
            max-width: 85px;
        }

        #pageList tr.check {
            background: #dff0d8;
            color: #222121;
        }

        #OpenDate {
            width: 240px !important;
            max-width: 300px !important;
        }

        #message {
            background-color: red;
        }
        .rowGray{
              color:#c1bbbb;
        }
    </style>

</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="main" runat="Server">
    <div class="system-box">
        <div class="right-side">
            <%-- 按钮--%>
            <div class="btns-container"></div>
            <%--新增弹出框begin--%>
            <div class="modal inmodal" id="addWindow" tabindex="-1" role="dialog" aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content animated bounceInRight">
                        <div class="modal-header">
                            <span class="editTitle"></span>
                            <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span> <span class="sr-only">关闭</span> </button>
                        </div>
                        <div id="message" style="display: none"></div>
                        <div class="modal-body clearfix">
                            <form class="form-horizontal">

                                <div class="form-group">
                                    <label class="col-sm-3 control-label">区&nbsp;&nbsp;域:</label>
                                    <div class="col-sm-9">
                                        <select class="form-control  input-w240 required" id="Area">
                                        </select>
                                        <input type="text" id="OldArea" name="OldArea" placeholder="" class="hide" readonly />
                                        <input type="text" id="ShopPlanID" name="ShopPlanID" placeholder="" class="hide" value="0" readonly />

                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="ShopCode" class="col-sm-3 control-label">店铺级别:</label>
                                    <div class="col-sm-9">
                                        <select class="form-control input-w240 required" id="Level">
                                        </select>
                                        <input type="text" id="OldLevel" name="OldLevel" placeholder="" class="hide" />
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="ShopID" class="col-sm-3 control-label">开店时间:</label>
                                    <div class="col-sm-9">
                                        <input name="search-date" placeholder="开店时间" datacol="yes" err="开店时间" checkexpession="NotNull" class="form-control layer-date required" id="OpenDate" />
                                        <input type="text" id="OldOpenDate" name="OldOpenDate" placeholder="" class="hide" readonly />
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="MaterialID" class="col-sm-3 control-label">开店数量:</label>
                                    <div class="col-sm-9">
                                        <input type="text" id="ShopNum" name="ShopNum" placeholder="" datacol="yes" err="开店数量" checkexpession="NotNull" maxlength="10" class="form-control required input-w240" />
                                        <input type="text" id="OldShopNum" name="OldShopNum" placeholder="" class="hide" />
                                    </div>
                                </div>
                            </form>
                            <div style="text-align: center"><span style="color: red; font-size: 10px;">说明：默认为每月的25号为开店日</span></div>
                            <br />
                        </div>
                        <div class="modal-footer">
                            <button type="button" id="addModuleBtn" class="btn btn-primary">保存</button>
                            <button type="button" id="closeAddBox" class="btn btn-white" data-dismiss="modal">关闭</button>
                        </div>
                    </div>
                </div>
            </div>
            <%--新增弹出框end--%>

            <div class="condition clearfix">
                <label>区域</label>
                <select class="form-control input-w120" id="search-area">
                    <option value="">全部</option>
                </select>
                <label>店铺级别</label>
                <select class="form-control input-w170" id="search-level">
                    <option value="">全部</option>
                </select>
                <label>开店时间</label>
                <input name="search-date" placeholder="开店时间" class="form-control layer-date  input-w110" id="search-OpenDate" />
            </div>

            <div class="right-content-box clearfix">
                <div class="ibox-content">
                    <table class="footable table table-stripped">
                        <thead></thead>
                        <tbody id="pageList"></tbody>
                    </table>
                </div>
            </div>

            <div class="pageControl"></div>
        </div>
    </div>

</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="footer" runat="Server">
    <script src="../assets/js/jquery-ui-1.10.4.min.js"></script>
    <script src="../assets/js/plugins/layer/laydate/laydate.js"></script>
    <script src="../assets/img/validate/learunui-validator.js"></script>
    <script src="../assets/js/page/pageControl.js"></script>
    <script src="../assets/js/page/rScroll.js"></script>
    <script src="../assets/js/page/tableControl.js"></script>
    <script src="../assets/js/plugins/webuploader/webuploader.min.js"></script>
    <script src="../assets/js/framework.js"></script>
    <script src="../assets/js/plugins/bootstrap-typeahead/bootstrap-typeahead.js"></script>

    <script src="../assets/js/plugins/iCheck/icheck.min.js"></script>
    <script src="../assets/js/plugins/iCheck/icheckAll.js"></script>
    <script src="../assets/js/plugins/stepper/stepper.widget.js"></script>
    <script src="../assets/js/plugins/boxdrop/jquery.boxdrop.js"></script>
    <script src="../assets/js/plugins/bootstrap-datepicker/bootstrap-datepicker.min.js"></script>
<%--    <script src="../assets/js/jquery-rowcol-span.min.js"></script>--%>

    <script>
        $('document').ready(function () {
            //模块ID
            var ModuleID = Y.getUrlParam("ModuleID");
            //当前页数
            var page = 1;
            commonUtil.loadBtnList(ModuleID, function () {
                $('#editBtn').attr("disabled", "disabled");
                rScroll();
            });
            GetBasOperationAreaList(true);
            //获取店铺等级
            //commonUtil.bindDwGlobalVariables({ dictValue: '店铺级别' }, ['#search-level']);
            //commonUtil.bindDwGlobalVariables({ dictValue: '店铺级别' }, ['#Level']);
            commonUtil.bindGlobalVariableListShop({ InfoType: 'ShopLevel' }, ['#search-level']);
            commonUtil.bindGlobalVariableListShop({ InfoType: 'ShopLevel' }, ['#Level']);


            //获取区域
            // commonUtil.bindDwGlobalVariables({ dictValue: '商品区域' }, ['#search-area']);

            // 
            function GetBasOperationAreaList(callback) {
                $('#search-area').empty();
                $('#search-area').append('<option value="">全部</option>');
                Y.API2('ShopPlanning', 'GetBasOperationAreaList', {}, function (data) {
                    if (data.Success == false) {
                        swal(data.Message, '', 'error');
                    } else {
                        var html = '';
                        var html1 = '';
                        data.map(function (item) {
                            html1 += '<option value=' + item.OperationAreaID + '>' + item.OperationAreaName + '</option>';
                            html += '<option value=' + item.OperationAreaID + '>' + item.OperationAreaName + '</option>';
                        });
                        $('#search-area').append(html);
                        $('#Area').append(html1);

                        if (typeof callback === "function") {
                            callback();
                        }
                    }
                });
            }


            $('#search-OpenDate').datepicker({
                format: "yyyy-mm",
                startView: 1,
                minViewMode: 1,
                language: "zh-CN",
                autoclose: true
            });


            $('#OpenDate').datepicker({
                format: "yyyy-mm",
                startView: 1,
                minViewMode: 1,
                language: "zh-CN",
                autoclose: true
            });

            //var GetCurrData = function () {
            //    var data = new Date();
            //    var year = data.getFullYear();
            //    var month = data.getMonth();
            //    month = (parseInt(month) + 1);
            //    if (month < 10)
            //        month = "0" + month;
            //    return year + "-" + month;
            //}

            //$("#search-OpenDate").val(GetCurrData());


            var dataList = [];
            IsCreate = true;
            //处理表头
            if ($('.footable thead').children().size() == 0) {
                tableControl.initThead('.footable',
                    [
                        {
                            trClass: '',
                            children: [
                                { tdText: '', c: 0, r: 0, tdHtml: '<input type="checkbox" id="checkAllPlan" />', tdId: '', tdClass: 'diy-td-w30' },
                                { tdText: '区域', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'diy-td-w50' },
                                { tdText: '开店时间', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'diy-td-w150' },
                                { tdText: '店铺级别', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'diy-td-w100' },
                                { tdText: '开店数量', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'diy-td-w50' }
                            ]
                        }
                    ]);
            }


            //只能输入数字
            $('#ShopNum').bind('input propertychange', function () {

                var myReg = /^[\u4e00-\u9fa5]+$/;
                if (myReg.test($(this).val())) {
                    $(this).val("");
                }

                if (isNaN($(this).val())) {
                    $(this).val($(this).val().substring(0, $(this).val().length - 1));
                    return;
                }
                //将中文替换掉
                $(this).val($(this).val().replace(/[^\x00-\xff]/g, ''));

                //最多为9999家
                if (parseInt($(this).val()) > 10000) {
                    $(this).val($(this).val().substring(0, $(this).val().length - 1));
                    return
                }
            });


            var pageList = [];
            //获取列表
            var loadList = function () {
                $('#editBtn').attr('disabled', 'disabled');

                pageControl.init('ShopPlanning', 'GetShopPlanninglist', {
                    Area: $('#search-area').val(),
                    ShopLevel: $('#search-level').val(),
                    OpenDate: $('#search-OpenDate').val().trim(),
                    Page: page,
                    Size: 50,
                    needLayer: true,
                    alwaysCallBack: function () {
                        $('#pageList').empty();
                    }
                }, function (result) {
                    pageList = [];
                    page = result.page;
                    var tBody = [];
                    if (!Y.checkNull(result.data)) {
                        //默认先隐藏
                        $('#deleteBtn').attr('disabled', 'disabled');
                        if (result.data.Items.length > 0) {
                            //有值，可以编辑  在选择后控制
                            $('#deleteBtn').removeAttr('disabled');
                            dataList = result.data.Items;
                            var IsEmpty = '0';
                            result.data.Items.map(function (items, i) {
                                //pageList.push(item);
                                items.map(function (item, j) {
                                    var tempChild = [];
                                    //如果日期小于当前，则显示灰色
                                    var DateChang = false;
                                    var d1 = new Date(item.NowTime.substring(0, 7).replace(/\-/g, "\/")+'/01');
                                    var d2 = new Date(item.OpenDate.replace(/\-/g, "\/") + '/01');
                                    if (d1 > d2 && item.NowTime.substring(0, 7) != item.OpenDate) {//当前月不变灰
                                        DateChang = true
                                    }
                                    if (j == 0) {
                                        tempChild = [
                                            {
                                                tdText: '',
                                                c: 0,
                                                r: items.length,
                                                tdHtml:
                                                '<input type="checkbox" class="checkPlan" data-index="' + i + '" />',
                                                tdId: '',
                                                tdClass: ''
                                            },
                                            {
                                                tdText: '',
                                                c: 0,
                                                r: items.length,
                                                tdHtml: '<span style="display:inline-block; width:100px;">' +
                                                (item.CompanyID || IsEmpty) + '</span>',
                                                tdId: '',
                                                tdClass: 'hide CompanyID'
                                            },
                                            {
                                                tdText: '',
                                                c: 0,
                                                r: items.length,
                                                tdHtml: '<span style="display:inline-block; width:100px;">' +
                                                (item.OperationAreaID || IsEmpty) + '</span>',
                                                tdId: '',
                                                tdClass: 'hide OperationAreaID'
                                            },
                                            {
                                                tdText: '',
                                                c: 0,
                                                r: items.length,
                                                tdHtml: '<span style="display:inline-block; width:100px;">' +
                                                (item.ShopPlanID || IsEmpty) + '</span>',
                                                tdId: '',
                                                tdClass: 'hide ShopPlanID'
                                            },
                                            {
                                                tdText: '',
                                                c: 0,
                                                r: items.length,
                                                tdHtml: '<span style="display:inline-block; width:50px">' +
                                                (item.OperationAreaName || IsEmpty) + '</span>',
                                                tdId: '',
                                                tdClass: 'OperationAreaName'
                                            },
                                            {
                                                tdText: '',
                                                c: 0,
                                                r: items.length,
                                                tdHtml: '<span style="display:inline-block; width:150px;">' + (item.OpenDate || IsEmpty) + '</span>',
                                                //tdHtml: DateChang == false ? '<span style="display:inline-block; width:150px;">' + (item.OpenDate || IsEmpty) + '</span>' :
                                                //    '<span style="display:inline-block; width:150px;color:#c1bbbb">' + (item.OpenDate || IsEmpty) + '</span>',
                                                tdId: '',
                                                tdClass: 'OpenDate'
                                            },
                                            {
                                                tdText: '',
                                                c: 0,
                                                r: items.length,
                                                tdHtml: '<span style="display:inline-block; width:100px;">' +
                                                (item.dictName || IsEmpty) + '</span>',
                                                tdId: '',
                                                tdClass: 'dictName'
                                            },
                                            {
                                                tdText: '',
                                                c: 0,
                                                r: items.length,
                                                tdHtml: '<span style="display:inline-block; width:100px;">' +
                                                (item.dictValue || IsEmpty) + '</span>',
                                                tdId: '',
                                                tdClass: 'hide dictValue'
                                            },

                                            {
                                                tdText: '',
                                                c: 0,
                                                r: items.length,
                                                tdHtml: '<span style="display:inline-block; width:100px;">' +
                                                (item.ShopNum || IsEmpty) + '</span>',
                                                tdId: '',
                                                tdClass: 'ShopNum'
                                            }

                                        ];
                                    }
                                    var tempTr = {
                                        trClass: (i % 2 == 0 ? 'gradeX footable-even' : 'gradeX footable-odd') + ' '
                                        + item.OperationAreaName + '_'
                                        + item.OpenDate + '_'
                                            + item.dictName + '_' + (DateChang ? " rowGray" :""),
                                        children: tempChild
                                    };
                                    tBody.push(tempTr);
                                });
                            });
                        }
                        rScroll();
                    }
                   
                    tableControl.initTbody('.footable', (tBody.length > 0 ? tBody : null), 13, null);
                   // _w_table_rowspan(".footable", 5); 
                    //选择全部插件
                    $(".footable").icheckAll({
                        checkObj: ".checkPlan",//表格下面的选择控件对象 选择器
                        checkAllObj: "#checkAllPlan",//全选 选择器
                        clickoutBoxCheck: false,//点击行 不选中
                        checkboxMargin: "4px 0 0 0 "//上右下左
                    });
                });
            }
            //页面加载
            loadList();

            //查询按钮
            $('.btns-container').on('click', '#btn-search', function () {
                page = 1;
                loadList();
            });
            //选中记录样式变化
            $('#pageList').on('click', 'tr', function () {

                $('.footable tr').removeClass('check');
                $(this).addClass("check");
                $('#editBtn').removeAttr('disabled');

            });


            //删除按钮
            commonUtil.initDeleteBtnEvent({
                callBack: function () {
                    submitList = [];
                    $(".footable").find('.checked').each(function () {
                        var ShopPlanID = $(this).parents("td").siblings(".ShopPlanID").text();
                        var OpenDate = $(this).parents("td").siblings(".OpenDate").text();
                        submitList.push({
                            ShopPlanID: ShopPlanID,
                            OpenDate: OpenDate
                        });
                    });
                    if (submitList.length == 0) {
                        swal('请选择要删除的项');
                        return false;
                    }
                    // console.table(submitList);
                    Y.API2('ShopPlanning', 'Remove',
                        {
                            List: submitList
                        }
                        , function (data) {
                            layer.closeAll('dialog');
                            if (data.Success == false) {
                                swal('删除失败', data.Message, 'error');
                            } else {
                                swal('删除成功', '该信息已被你永久删除', 'success');
                                loadList();
                            }
                        });
                }
            });

            //新增按钮
            $('.btns-container').on('click', '#addBtn', function () {
                $('.editTitle').text('新增数据');
                $('#addModuleBtn').show();
                IsCreate = true;
                $("#shopSearch").removeAttr('readonly');
                $("#DisplayQty").removeAttr('readonly');
                resetInput();
            });
            var resetInput = function () {

                $('#OpenDate').val("");
                $('#ShopNum').val("");
                var data = sessionStorage.getItem('login-info');
                var d = $.parseJSON(data);
            };

            //编辑按钮
            $('.btns-container').on('click', '#editBtn', function () {
                $('.editTitle').text('编辑数据');
                $('#addModuleBtn').show();
                resetInput();
                IsCreate = false;
                loadDetail();
            });
            //获取选中行的内容,填充到打开的框内
            var loadDetail = function () {
                //有的会加载出来两个 
                var $check = $('.footable').find('.check')[0];
                var CompanyID = $($check).find('.CompanyID').find("span").html();
                var ShopPlanID = $($check).find('.ShopPlanID').find("span").html();
                var OpenDate = $($check).find('.OpenDate').find("span").html();
                var ShopNum = $($check).find('.ShopNum').find("span").html();
                var Level = $($check).find('.dictValue').find("span").html();
                var Area = $($check).find('.OperationAreaID').find("span").html();

                //OperationAreaID
                if (CompanyID == "") {
                    swal("数据异常，公司编码不能为空，请刷新页面重试", '', 'error');
                    return false;
                }
                /*
                 OpenDate  OldOpenDate
                 ShopNum OldShopNum
                 Level  OldLevel
                 Area  OldArea
                */
                $('#ShopPlanID').val(ShopPlanID);
                $('#OpenDate').val(OpenDate);
                $('#ShopNum').val(ShopNum);
                $('#Level').val(Level);
                $('#Area').val(Area);

                //保存旧的
                $('#OldOpenDate').val(OpenDate);
                $('#OldShopNum').val(ShopNum);
                $('#OldLevel').val(Level);
                $('#OldArea').val(Area);
            }


            //弹窗的保存操作
            $('#addModuleBtn').click(function () {
                if (!CheckDataValid('.form-horizontal')) {
                    return false;
                }
                var action = "";
                var successText = "";
                if (IsCreate) {
                    action = "Insert";
                    successText = '新增成功';
                    $('#ShopPlanID').val("0");
                }
                else {
                    action = "Update";
                    successText = '编辑成功';
                    //效验是否未更改内容
                    if (CheckIsChang()) {
                        tipCss($(this), "数据未更改"); return false;
                    }
                }
                //整数取整后不等于自己。则不是整数
                if (parseInt($('#ShopNum').val(), 10) != $('#ShopNum').val()) {
                    $('#ShopNum').val(parseInt($('#ShopNum').val(), 10));
                    tipCss($(this), "数量必须为整数 ！"); return false;
                }

                if ($('#ShopNum').val() < 1) {
                    tipCss($(this), "数量不能小于1 ！"); return false;
                }
                if ($('#ShopNum').val() >= 10000) {
                    tipCss($(this), "数量不能超过一万"); return false;
                }
                layer.msg('玩命加载中……', { icon: 16, shade: 0.5, time: 0, maxWidth: 200 });
                Y.API2('ShopPlanning', action, {
                    ShopPlanID: $('#ShopPlanID').val(),
                    OpenDate: $('#OpenDate').val(),
                    ShopNum: $('#ShopNum').val(),
                    Level: $('#Level').val(),
                    Area: $('#Area').val(),
                    //保存旧的
                    OldOpenDate: $('#OldOpenDate').val(),
                    OldShopNum: $('#OldShopNum').val(),
                    OldLevel: $('#OldLevel').val(),
                    OldArea: $('#OldArea').val()
                }, function (data) {
                    layer.closeAll('dialog');
                    if (data.Success == false) {
                        //tipCss($(this), data.Message); 
                        swal(data.Message, '', 'error');
                    } else {
                        swal(successText, '', 'success');
                        //关闭新建  or 编辑框  
                        $('#closeAddBox').click();
                        //刷新列表
                        loadList();
                    }
                });
            });
            //修改时 验证是否有修改内容
            var CheckIsChang = function () {
                if ($('#ShopPlanID').val() == 0) {
                    return false;
                }
                var OldOpenDate = $('#OldOpenDate').val();
                var OldShopNum = $('#OldShopNum').val();
                var OldLevel = $('#OldLevel').val();
                var OldArea = $('#OldArea').val();


                var OpenDate = $('#OpenDate').val();
                var ShopNum = $('#ShopNum').val();
                var Level = $('#Level').val();
                var Area = $('#Area').val();

                if (OpenDate == OldOpenDate && OldShopNum == ShopNum && OldLevel == Level && OldArea == Area)
                    return true;

                return false;
            }
        });
    </script>
</asp:Content>



